<template>
	<view class="Wallet">
		<u-navbar :auto-back="true" title="我的钱包" bg-color="transparent"></u-navbar>
		<view class="bgBack"></view>
		<view class="topBox">
			<view class="topInfo">
				<view class="nickname">
					<u-image :src="userInfo.avatar" width="55rpx" height="55rpx" radius="55rpx" customStyle="border: 1px solid yellow;"/>
					<text>{{ userInfo.username }}</text>
				</view>
				<view class="money">￥ {{ money }}</view>
				<view class="tips">可提现余额（元）</view>
				<view class="tixian" @click="$goUrl('/pages/mine/wallet/cash','to')"><text>去提现</text></view>
			</view>
			<view class="incomebox">
				<view class="income"><text>今日预计收益：</text><text class="money">￥60.98</text></view>
				<view class="income"><text>昨日收益：</text><text class="money">￥60.98</text></view>
			</view>
			<view class="liushuibox">
				<view class="top">
					<view class="title">钱包流水</view>
					<view class="more flex_box" @click="$goUrl('/pages/mine/wallet/record','to')">查看全部 <u-icon name="arrow-right" color="#999999"></u-icon></view>
				</view>
				<view class="list-box">
					<view class="item" v-for="(item, index) in list" :key="index">
						<view class="leftbox">
							<u-image width="100rpx" height="100rpx" :src="`/static/lsicon${item.dis_type}.png`"/>
							<view class="typetime">
								<text class="type">
									{{item.dis_type == 1 ? '线路出行返佣' : (item.dis_type == 2 ? '景区升级分佣' : '提现')}}
								</text>
								<text class="time">{{item.createtime}}</text>
							</view>
					    </view>
						<text class="money" :class="{'out': item.dis_type == 3}">{{item.dis_type == 3 ? '-' : '+'}} ￥ {{ item.money }}</text>					
					</view>
				</view>
				<view v-if="listStatus==='nomore'&&list.length===0" class="empty_box">
					<u-empty mode="data" icon="/static/empty/data.png" text="亲，该时间段还没有流水记录哦！"></u-empty>
				</view>
				<block v-else>
					<u-loadmore :line="true" @loadmore="getMore" :status="listStatus"></u-loadmore>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	import { getInfo, userFlow } from '@/common/http.api.js';
	let that;
	export default {
		data() {
			return {
				money: '',
				btnStyle: {
					width: '128rpx',
					height: '68rpx',
					color: '#1E272E',
					margin: '0'
				},
				list: [],
				listStatus: 'loading',
				params: {
					page: 1,
				},
			}
		},
		onLoad() {
			that = this;
			that.getList();
		},
		onShow() {
			that.getInfo();
			that.listStatus = 'nomore'
		},
		onReachBottom() {
			that.getMore();
		},
		methods: {
			getInfo() {
				getInfo()
					.then(res => {
						that.money = res.data.money
					})
					.catch(err => {
						uni.$u.toast(err.msg);
					});
			},
			// 点击加载更多
			getMore(){
				that.listStatus==="loadmore"&&(that.params.page++,that.listStatus = "loading",that.getList());
			},
			getList(){
				that.params.type = 1;
				userFlow({params: that.params}).then(res => {
					let list = res.data.data;
					that.listStatus = list.length < res.data.per_page ? "nomore" : "loadmore";
					that.list = [...that.list,...list];
				}).catch(err => {
					uni.$u.toast(err.msg);
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
	.Wallet{
		min-height: 100vh;
		background-color: #F6F8FA;
		.bgBack {
			width: 750rpx;
			height: 554rpx;
			background: linear-gradient(135deg, #BBF4E9, #EDFFFC, #EDFFFC, #EDFFFC, #CCF6F5);
		}
		.topBox {
			margin-top: -392rpx;
			z-index: 300;
			padding: 30rpx;
			z-index: 300;
			position: relative;
			.topInfo {
				padding: 36rpx;
				width: 690rpx;
				background: linear-gradient(-12deg, #46D5CD, #3DC8C0);
				border-radius: 24rpx;
				gap: 14rpx;
				.nickname {
					display: flex;
					align-items: center;
					gap: 20rpx;
					text {
						width: 158rpx;
						font-family: Source Han Sans CN;
						font-weight: 500;
						font-size: 32rpx;
						color: #FFFFFF;
					}
				}
				.money {
					font-family: Source Han Sans CN;
					font-weight: 500;
					font-size: 32rpx;
					color: #FFFFFF;
					margin-top: 35rpx;
				}
				.tips {
					font-family: Source Han Sans CN;
					font-weight: 400;
					font-size: 24rpx;
					color: #FFFFFF;
				}
			}
			.tixian {
				width: 140rpx;
				height: 64rpx;
				background: #FFFFFF;
				border-radius: 32rpx 0rpx 0rpx 32rpx;
				position: absolute;
				right: 30rpx;
				top: 170rpx;
				text-align: center;
				line-height: 64rpx;
				text {
					width: 93rpx;
					font-family: Source Han Sans CN;
					font-weight: 500;
					font-size: 32rpx;
					color: #4BD0C8;
				}
			}
			.incomebox {
				width: 690rpx;
				background: #FFFFFF;
				border-radius: 24rpx;
				display: flex;
				padding: 20rpx;
				justify-content: space-between;
				align-items: center;
				margin-top: 20rpx;
				display: none;
				.income {
					text {
						font-family: Source Han Sans CN;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
					}
					.money {
						font-family: Source Han Sans CN;
						font-weight: bold;
						font-size: 24rpx;
						color: #51D8D0;
					}
				}
			}
			.liushuibox {
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-top: 20rpx;
				padding: 0 20rpx;
				.top {
					display: flex;
					justify-content: space-between;
					align-items: center;
					border-bottom: 5rpx solid #EEEEEE;
					.title {
						font-family: Source Han Sans CN;
						font-weight: bold;
						font-size: 32rpx;
						color: #353535;
						padding: 10rpx;
					}
					.more {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 26rpx;
						color: #999999;
						padding: 10rpx;
					}
				}
				.list-box {
					display: flex;
					justify-content: space-between;
					margin: 30rpx auto;
					flex-direction: column;
					.item {
						display: flex;
						justify-content: space-between;
						align-items: center;
						margin: 0 0 30rpx 0;
						width: 100%;
						.leftbox {
							display: flex;
							flex-direction: row;
							align-items: center;
							gap: 20rpx;
						}
						.typetime {
							display: flex;
							flex-direction: column;
							gap: 10rpx;
							.type {
								font-family: Source Han Sans CN;
								font-weight: bold;
								font-size: 32rpx;
								color: #2A2C30;
							}
							.time {
								font-family: Source Han Sans CN;
								font-weight: 400;
								font-size: 28rpx;
								color: #AAAAAA;
							}
						}
						.money {
							font-family: Source Han Sans CN;
							font-weight: bold;
							font-size: 32rpx;
							color: #30B2AB;
						}
						.out {
							color:#E22525;
						}
					}
				}
				.empty_box {
					padding: 100rpx 0 50rpx 0;
				}
			}
		}
	}
</style>
